package io.github.ex;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.logging.Level;

public class PPStream extends ByteArrayOutputStream {
    private final String separator = System.getProperty("line.separator");
    private final Level level;
    PrintStream out,err;

    public PPStream(Level level, PrintStream out,PrintStream err) {
        this.level = level;
        this.out = out;
        this.err = err;
    }



    @Override
    public void flush() throws IOException {

        System.out.println("A");

        synchronized (this) {
            super.flush();
            String record = this.toString();
            super.reset();

            if ((!record.isEmpty()) && (!record.equals(separator))) {
                if(level == Level.INFO){
                    out.println("[STD]"+record);
                }else if(level == Level.WARNING){
                    out.println(record);
                }else if(level == Level.SEVERE){
                    err.println(record);
                }else if(level == Level.CONFIG){

                }

            }
        }
    }
}
